// pages/listing/listing.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status: 1,
    set_Img: 'https://api.yipaiju.com/resources/images/wawa/jia_1.png',
    steps: [{
        text: '提交',
        inactiveIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_1.png',
        activeIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_11.png',
      },
      {
        text: '审核',
        inactiveIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_2.png',
        activeIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_22.png',
      },
      {
        text: '出售',
        inactiveIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_3.png',
        activeIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_33.png',
      },
      {
        text: '完成',
        inactiveIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_4.png',
        activeIcon: 'https://api.yipaiju.com/resources/images/wawa/fanpqy_44.png',
      },
    ],
    review: [{
        text: '已提交',
        desc: '市场专员 李太白',
        inactiveIcon: 'https://api.yipaiju.com/resources/images/wawa/sh_2.png',
        activeIcon: 'https://api.yipaiju.com/resources/images/wawa/sh_22.png',
      },
      {
        text: '待审核',
        desc: '市场部 和珅',
        inactiveIcon: 'https://api.yipaiju.com/resources/images/wawa/sh_2.png',
        activeIcon: 'https://api.yipaiju.com/resources/images/wawa/sh_22.png',
      },
    ],
    active: 0,
    footerBtn: '立即提交',
    reviewActive: 0,
    admin: 1,
    userId: '',
    Model: false,
    customize: '',
    region: ['请选择', '请选择', '请选择'],
    show0: false, //控制下拉列表的显示隐藏，false隐藏、true显示
    show1: false, //控制下拉列表的显示隐藏，false隐藏、true显示
    direction: ['请选择', '东', '南', '西', '北'], //下拉列表的数据
    floor: ['请选择', '1-5年', '6-10年', '10年以上'], //下拉列表的数据
    index: 0, //选择的下拉列表下标
    Index: 0,
    date: '2020-01-01',
    reDate: '2020-01-01',
    only: -1,
    degree: -1,
    user: -1,
    share: -1,
    seize: -1,
    sex: -1,
    mortgage: [{}],
    seal: [{}],
    select: [0, 0, 0, 0, 0],
    username: '',
    phone: '',
    referrer: '',
    information: [{
      imgs: [{
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }, {
        Imgs: []
      }],
      inputs: [{
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }, {
        text: ''
      }]
    }],
    list: {},
    info: {},
    disabled: true,
    reviewDetail: ''
  },
  imgSubmit(information) {
    var imgs = {
      periphery_community: information.imgs[0],
      insideHouse: information.imgs[1],
      lease_contract: information.imgs[2],
      estate_license: information.imgs[3],
      invoice: information.imgs[4],
      house_property: information.imgs[5],
      judgment_doc: information.imgs[6],
      assessment_report: information.imgs[7],
      exclusive_agreement: information.imgs[8]
    }
    console.log(imgs);
  },
  // api(information) {
  //   var that = this;
  //   var region = that.data.region;
  //   console.log(information)
  //   console.log(information.inputs[0].text)
  //   var data = {
  //     name: information.inputs[0].text,
  //     phone: information.inputs[1].text,
  //     province: region[0],
  //     city: region[1],
  //     district: region[2],
  //     location: information.inputs[2].text,
  //     residentialQuarterName: information.inputs[3].text,
  //     unitNo: information.inputs[23].text,
  //     houseLevel: information.inputs[4].text,
  //     houseTotalLevel: information.inputs[5].text,
  //     builtUpAreaSquareCentimeter: information.inputs[6].text,
  //     insideAreaSquareCentimeter: information.inputs[7].text,
  //     bedromm: information.inputs[8].text,
  //     livingroom: information.inputs[9].text,
  //     toilet: information.inputs[10].text,
  //     kutchen: information.inputs[11].text,
  //     balcony: information.inputs[12].text,
  //     orientation: that.data.select1,
  //     houseAge: information.inputs[13].text,
  //     elevator: that.data.sexText, //电梯
  //     decoration: that.data.select2,
  //     uploadTime: that.data.date,
  //     onlyHouse: that.data.onlyText, //唯一住房
  //     owningType: that.data.shareText, //共有情况
  //     degree: information.inputs[14].text, //附属学位
  //     havingDegree: that.data.degreeText, //是否占用学位
  //     houser_user: that.data.userText, //房屋使用人
  //     remainingLease: that.data.reDate,
  //     seizure: that.data.seizeText, //是否存在查封
  //     rentYuan: information.inputs[15].text,
  //     estimatePriceYuan: information.inputs[16].text,
  //     marketPriceYuan: information.inputs[17].text,
  //     intentionPriceYuan: information.inputs[18].text,
  //     title: information.inputs[19].text,
  //     specificRequirement: information.inputs[20].text,
  //   }
  //   console.log(data)
  //   console.log(that.data.mortgage)
  //   // getApp().ports.fptj({
  //   //   data: data
  //   // }).then((res) => {
  //   //   console.log(res, '成功'); 
  //   // }).catch(() => {
  //   //   console.error('出啥错了？');
  //   // });
  // },
  setInfo(e) {
    var that = this;
    var info = {};
    var region = that.data.region;
    console.log(e)
    info.clientName = e.clientName;
    info.phone = e.phone;
    region[0] = e.province;
    region[1] = e.city;
    region[2] = e.district;
    info.location = e.location;
    info.residentialQuarterName = e.residentialQuarterName;
    info.unitNo = e.unitNo;
    info.houseLevel = e.houseLevel;
    info.houseTotalLevel = e.houseTotalLevel;
    info.builtUpAreaSquareCentimeter = e.builtUpAreaSquareCentimeter;
    info.insideAreaSquareCentimeter = e.insideAreaSquareCentimeter;
    info.bedroom = e.bedroom;
    info.livingroom = e.livingroom;
    info.toilet = e.toilet;
    info.kitchen = e.kitchen;
    info.balcony = e.balcony;

    if (e.orientation) that.data.select1 = e.orientation; //朝向

    info.houseAge = e.houseAge;
    if (e.elevator) that.data.sex = (e.elevator == '有' ? 0 : 1);
    if (e.decoration) that.data.select2 = e.decoration; //装修情况

    that.data.date = e.uploadTime;
    if (e.onlyHouse) that.data.only = (e.onlyHouse == '是' ? 0 : 1);
    if (e.owningType) that.data.share = (e.owningType == '是' ? 0 : 1);

    info.degree = e.degree; //附属学位
    if (e.havingDegree) that.data.degree = (e.havingDegree == '是' ? 0 : 1); //是否占用学位
    if (e.house_user == '业主') {
      that.data.user = 0
    } else if (e.house_user == '租客') {
      that.data.user = 1
    } else {
      that.data.user = 2
    }

    // that.data.user = e.house_user; //房屋使用人
    that.data.reDate = e.remainingLease;
    that.data.date = e.registerTime;

    info.confiscator1 = e.confiscator1;
    info.seizureAmount1 = e.seizureAmount1;

    if (e.seizure) that.data.seize = (e.seizure == '是' ? 0 : 1); //是否存在查封

    info.rentYuan = e.rentYuan;
    info.estimatePriceYuan = e.estimatePriceYuan;
    info.marketPriceYuan = e.marketPriceYuan;
    info.intentionPriceYuan = e.intentionPriceYuan;
    info.title = e.title;
    info.specificRequirement = e.specificRequirement;
    info.mortgage1 = e.mortgage1;
    if (e.mortgage2) info.mortgage2 = e.mortgage2;
    if (e.mortgage2PriceYuan) info.mortgage2PriceYuan = e.mortgage2PriceYuan;
    if (e.seizure_amount2) info.seizure_amount2 = e.seizure_amount2;
    if (e.confiscator2) info.confiscator2 = e.confiscator2;
    if (e.mortgage2PriceYuan) info.mortgage2PriceYuan = e.mortgage2PriceYuan;
    info.mortgage1PriceYuan = e.mortgage1PriceYuan;
    info.recommender = e.recommender;
    info.tags = e.tags;
    that.setData({
      info: info,
      region: region,
      reDate: that.data.reDate,
      date: that.data.date,
      select1: that.data.select1,
      select2: that.data.select2,
      sex: that.data.sex,
      only: that.data.only,
      share: that.data.share,
      degree: that.data.degree,
      seize: that.data.seize,
      user: that.data.user
    })
    console.log(that.data.information)
  },
  onApi(data) {
    var that = this;
    var data = {
      id: that.data.id
    }
    var mortgage = that.data.mortgage;
    var seal = that.data.seal;
    var statuss = ['待提审', '待审核', '通过', '驳回', '拒绝'];
    var type = ['待提交', '已提交']
    var review = that.data.review;
    app.ports.fanpqy({
      data: data
    }).then((res) => {
      var res = res.data;
      getApp().ports.img({
        data: {
          relatedObjectId: res.discountHouseId
        }
      }).then((obj) => {
        var obj = obj.data;
        console.log(obj, '=======')
        console.log(that.data.information[0].imgs[0].Imgs)
        that.data.information[0].imgs[0].Imgs = obj.periphery_community
        that.data.information[0].imgs[1].Imgs = obj.banner
        that.data.information[0].imgs[2].Imgs = obj.lease_contract
        that.data.information[0].imgs[3].Imgs = obj.estate_license
        that.data.information[0].imgs[4].Imgs = obj.invoice
        that.data.information[0].imgs[5].Imgs = obj.house_property
        that.data.information[0].imgs[6].Imgs = obj.judgment_doc
        that.data.information[0].imgs[7].Imgs = obj.assessment_report
        that.data.information[0].imgs[8].Imgs = obj.exclusive_agreement
        that.setData({
          information: that.data.information
        })
      }).catch(() => {});
      console.log(res.discountHouse, '====')
      if (res.submitStatus) review[0].text = type[res.submitStatus]
      if (res.submitTime) review[0].time = res.submitTime;
      if (res.marketManagerVertifyStatus) review[1].text = statuss[res.marketManagerVertifyStatus]
      if (res.marketManagerVertifyStatus == 3) review[1].text = '驳回' + ' ' + '驳回理由：' + res.rejectReason
      if (res.marketManagerVerificationFinishTime) review[1].time = res.marketManagerVerificationFinishTime;
      if (res.marketManagerVerificationFinishTime && res.marketManagerVertifyStatus == 2) that.data.reviewActive = 1;
      if (res.financialManagerVerificationFinishStatus) review[2].text = statuss[res.financialManagerVerificationFinishStatus]
      if (res.financialManagerVerificationFinishTime) review[2].time = res.financialManagerVerificationFinishTime;
      if (res.stage == 2) {
        that.data.active = 0
      } else if (res.stage == 3 || res.stage == 4) {
        that.data.active = 1
      } else if (res.stage == 5 || res.stage == 6) {
        that.data.active = 2
      } else if (res.stage == 7 || res.stage == 8) {
        that.data.active = 4
      }
      // res.url = '../listing/listing?id=' + res.id
      res.url = '../../subpackages/pages/listing/listing?id=' + res.id
      that.setInfo(res.discountHouse)
      res.time = getApp().timeFormat(res.discountHouse.uploadTime)

      if(res.marketerUser) that.data.review[0].desc = '市场专员' + ' ' + res.marketerUser.nickname;
      if(res.marketManagerUser) that.data.review[1].desc = '市场部' + ' ' + res.marketManagerUser.nickname;

      // getApp().ports.api26({
      //   data: [res.marketer, res.marketManager]
      // }).then((obj) => {
      //   var obj = obj.data;
      //   console.log(obj,'================')
      //   for (var i = 0; i < obj.length; i ++){
      //     if(res.marketer == obj[i].id) that.data.review[0].desc = '市场专员' + ' ' + obj[i].nickname;
      //     if(res.marketManager == obj[i].id)   that.data.review[1].desc = '市场部' + ' ' + obj[i].nickname;
      //   }
      //   // if (res.marketer == res.marketManager) {
      //   //   that.data.review[0].desc = '市场专员' + ' ' + obj[0].nickname;
      //   //   that.data.review[1].desc = '市场部' + ' ' + obj[0].nickname;
      //   // } 
      //   that.setData({
      //     review: that.data.review
      //   })
      // }).catch(() => {});
      that.setData({
        list: res,
        review: review,
        active: that.data.active,
        reviewActive: that.data.reviewActive
      })
    }).catch(() => {
      console.error('出错111');
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      identity: wx.getStorageSync('identity'),
      id: options.id,
      status: Number(options.status),
      userId: wx.getStorageSync('userId'),
      imageRoot: app.globalData.imageRoot
    })
    that.onApi()
    // console.log(options.id);
  },
  navTo(e) { //跳转
    console.log(e.currentTarget.dataset.url)
    var url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 
  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value
    })
  },
   // 上传图片
   chooseImg: function (e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    var information = that.data.information;
    console.log(information[0].imgs[status])
    // var Imgs = imgss[status];
    // console.log(Imgs)
    if (information[0].imgs[status].length >= 100) {
      this.setData({
        lenMore: 1
      });
      setTimeout(function () {
        that.setData({
          lenMore: 0
        });
      }, 2500);
      return false;
    }
    wx.chooseImage({
      // count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        console.log(res)
        var tempFilePaths = res.tempFilePaths;
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var Imgs = information[0].imgs[status].Imgs;
        // console.log(tempFilePaths + '----');
        for (var i = 0; i < tempFilePaths.length; i++) {
          if (Imgs.length >= 100) {
            that.setData({
              information: information
            });
            return false;
          } else {
            that.uploadzdy(tempFilePaths[i], e.currentTarget.dataset.category, Imgs, that.data.list.id || that.data.discountHouseId)
          }
        }
        that.setData({
          information: information
        });
        console.log(that.data.information, '=======');
      },
    });
  },
  uploadzdy(tempFilePaths, category, Imgs, id) { //图片临时路径、图片类型、所在素组用于预览、当前订单id
    let that = this;
      let photoType = tempFilePaths.substring(tempFilePaths.lastIndexOf(".") + 1, tempFilePaths.length)
      console.log(photoType)
      let content_types = '';
      if (photoType == 'png') {
        content_types = 'image/png'
      } else if (photoType == 'jpg' || photoType == 'jpeg') {
        content_types = 'image/jpeg'
      } else {
        wx.showToast({ //提示格式不支持
          title: '不支持当前格式！',
          icon: 'none',
          duration: 2000
        })
        return false //阻止上传
      }
      // photoType == "png"?content_types='image/png':content_types='image/jpeg'
      let json = {
        content_type: content_types
      } //只能是png/jpg、jpeg
      let data = {
        category: category, //图片类型(是指当前订单的那种图片，例如小区图片等等)
        filename: tempFilePaths, //图片临时地址
        relatedObjectId: id //图片的主体 比如，一张单有很多图片，那这些图片的relatedObjectId就是这张签约单的id
      }
      console.log(data)
      getApp().ports.api66({
        data,
        json
      }).then((res) => {
         console.log(res)
        var fs = wx.getFileSystemManager()
        wx.request({
          url: res.data.url,
          data: fs.readFileSync(tempFilePaths), //上传临时路径
          method: 'PUT',
          header: res.data.headers,
          success(res) {
            // 图片真实路径、30秒过期
            // let data = { object_name  : res.data.form.object }
            // getApp().ports.api67({data}).then((res)=>{
            //   console.log(res.data)
            // }).catch(()=>{console.error('拉取图片！')})
            console.log(res.data)
            Imgs.push({
              url: tempFilePaths,
              object_name: res.data.form.object
            });
            that.setData({
              information: that.data.information
            });
          }
        })
      }).catch(() => {
        console.error('上传失败！')
      })
    
    // return
   
    
  },
  // 预览图片
  previewImg: function (e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    var information = that.data.information;
    var Imgs = information[0].imgs[status].Imgs;
    var index = e.target.dataset.index
    console.log(Imgs[index])
    var images = []
    for (let i in Imgs) {
      images.push(that.data.imageRoot + Imgs[i].url)
    }
    wx.previewImage({
      //当前显示图片
      current: images[index],
      //所有图片
      urls: images
    })
  },
  //删除图片
  deleteImg: function (e) {
    var that = this;
    console.log(e)
    var object = e.currentTarget.dataset.name; //删除
    var status = e.currentTarget.dataset.status;
    var information = that.data.information;
    var Imgs = information[0].imgs[status].Imgs;
    var index = e.target.dataset.index
    let data = {
      object_name: object
    }
    getApp().ports.api68({
      data
    }).then((res) => { //删除图片
      // console.log(res)
      Imgs.splice(index, 1);
      that.setData({
        information: information
      })
    }).catch(() => {
      console.error('删除失败!')
    })
  },
  showModel() {
    this.setData({
      Model: true
    })
  },
  mortgageInput(e) {
    var that = this;
    var val = e.detail.value;
    var status = e.target.dataset.status;
    var type = e.target.dataset.type;
    var mortgage = that.data.mortgage;
    mortgage[status].id = status;
    mortgage[status][type] = val;
    that.setData({
      mortgage: mortgage
    })
    console.log(that.data.mortgage)
  },
  sealInput(e) {
    var that = this;
    var val = e.detail.value;
    var status = e.target.dataset.status;
    var type = e.target.dataset.type;
    var seal = that.data.seal;
    seal[status].id = status;
    seal[status][type] = val;
    that.setData({
      seal: seal
    })
    console.log(that.data.seal)
  },
  //添加框
  setBox(e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    var types = [that.data.mortgage, that.data.seal]
    var type = types[status];
    console.log(status)
    var arr = {
      id: '',
      name: '',
      money: ''
    };
    type.push(arr);
    if (status == 0) {
      that.setData({
        mortgage: type
      })
    } else if (status == 1) {
      that.setData({
        seal: type
      })
    }

    console.log(that.data.mortgage)
  },
  //删除框
  deleteBox(e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    var index = e.currentTarget.dataset.index;
    var type = e.currentTarget.dataset.type;
    var lists = [that.data.mortgage, that.data.seal];
    var list = lists[status];
    console.log(list)
    list.splice(index, 1)
    console.log(list)
    if (status == 0) {
      that.setData({
        mortgage: list
      });
    } else if (status == 1) {
      that.setData({
        seal: list
      });
    }

  },
  //跳转回退
  navBack(e) {
    wx.navigateBack({
      delta: 1
    })
  },
  //底部状态
  // stepActive(e) {
  //   var that = this;
  //   var footerBtn = that.data.footerBtn;
  //   var active = that.data.active;
  //   var status = that.data.status;
  //   var reviewActive = that.data.reviewActive;
  //   var review = that.data.review;
  //   console.log(status)
  //   if (status == 0) {
  //     //  that.submit()
  //     status = 1;
  //   } else if (status == 1) {
  //     reviewActive = 0;
  //     footerBtn = '等待审核'
  //     review[0].text = '已提交'
  //     status = 2;
  //   } else if (status == 2) {
  //     reviewActive = 1;
  //     review[1].text = '待审核'
  //     status = 3
  //   } else if (status == 3) {
  //     footerBtn = '放盘成功'
  //   }
  //   this.setData({
  //     active: active,
  //     footerBtn: footerBtn,
  //     status: status,
  //     reviewActive: reviewActive,
  //     review: review
  //   })
  // },
  customize(e) {
    var that = this;
    that.setData({
      customize: e.detail.value
    })
  },
  // reject(e) {
  //   var that = this;
  //   var reviewActive = that.data.reviewActive;
  //   var review = that.data.review;
  //   var active = that.data.active;
  //   switch (active) {
  //     case 0:
  //       reviewActive = 1;
  //       review[1].text = '已被驳回';
  //       review[1].activeIcon = 'cross'
  //       break;
  //       reviewActive = 2;
  //       review[2].text = '已被驳回';
  //       review[2].activeIcon = 'cross'
  //     default:
  //       break;
  //   }
  //   that.setData({
  //     review: review,
  //     reviewActive: reviewActive
  //   })
  // },
  // 点击下拉显示框
  selectTap(e) {
    console.log(e.currentTarget.dataset.status)
    if (e.currentTarget.dataset.status == 0) {
      this.setData({
        show0: !this.data.show0,
        show1: false
      });
    } else if (e.currentTarget.dataset.status == 1) {
      this.setData({
        show1: !this.data.show1,
        show0: false
      });
    }
  },
  // 点击下拉列表
  optionTap(e) {
    console.log(e.currentTarget.dataset.status)
    var that = this;
    let Index = e.currentTarget.dataset.index; //获取点击的下拉列表的下标

    if (e.currentTarget.dataset.status == 0) {
      this.setData({
        Index: Index,
        select1: that.data.direction[Index],
        show0: !this.data.show0
      });
    } else if (e.currentTarget.dataset.status == 1) {
      this.setData({
        index: Index,
        select2: that.data.floor[Index],
        show1: !this.data.show1
      });
    }
  },
  //单选
  check(e) {
    console.log(e)
    var that = this;
    var status = Number(e.currentTarget.dataset.status);
    var index = e.currentTarget.dataset.index;
    var text1 = ['有', '无'];
    var text2 = ['是', '否'];
    var text3 = ['单独所有', '共同所有'];
    var text4 = ['业主', '租客', '空置'];
    console.log(status)
    if (status == 0) {
      that.setData({
        sex: index,
        sexText: text1[index]
      })
    } else if (status == 1) {
      that.setData({
        only: index,
        onlyText: text2[index]
      })
    } else if (status == 2) {
      that.setData({
        share: index,
        shareText: text3[index]
      })
    } else if (status == 3) {
      that.setData({
        degree: index,
        degreeText: text2[index]
      })
    } else if (status == 4) {
      that.setData({
        user: index,
        userText: text4[index]
      })
    } else if (status == 5) {
      that.setData({
        seize: index,
        seizeText: text2[index]
      })
    }
    console.log(that.data.seizeText, '查封')
  },
  //多选选
  choose(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var select = this.data.select;
    if (index && select[index] != 1) {
      select[index] = 1
    } else {
      select[index] = 0
    }
    that.setData({
      select: select
    })
    console.log(select)
  },
  bindDateChange(e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    if (status == 0) {
      that.setData({
        date: e.detail.value
      })
    } else if (status == 1) {
      that.setData({
        reDate: e.detail.value
      })
    }
  },
  getInput(e) {
    var that = this;
    var status = e.currentTarget.dataset.status;
    // var value = e.detail.value;
    var information = that.data.information;
    var text = information[0].inputs[status].text = e.detail.value;
    that.setData({
      information: information
    })
  },
  submit(e) {
    var that = this;
    var _this = that.data;
    var information = _this.information[0];
    console.log(information)
    that.api(information)
    // var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
    // if (!myreg.test(that.data.phone)) {
    //     console.log('手机号格式不正确');
    //     wx.showToast({
    //       title: '手机号格式不正确',
    //       icon:'none'
    //     })
    //     return
    // } else {
    //     console.log('手机号格式正确')
    // }
    // information.checks = [_this.budget, _this.purpose, _this.area, _this.unit]
  },
  marketRefuse(e) { //市场拒绝
    var that = this;
    var data = {
      marketManagerVertifyStatus: 4
    };
    wx.showModal({
      title: '提示',
      content: '是否拒绝市场专员审核信息',
      success(res) {
        if (res.confirm) {
          that.market(data)
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  marketPass(e) { //市场通过
    console.log('市场通过')
    var that = this;
    var data = {
      marketManagerVertifyStatus: 2,
      priceYuan: Number(that.data.reviewDetail),
    };
    if (data.priceYuan) {
      wx.showModal({
        title: '提示',
        content: '是否通过市场专员审核信息',
        success(res) {
          if (res.confirm) {
            that.market(data)
            that.setData({
              reviewActive: 1
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.showToast({
        title: '请填写最终放盘价',
        icon: 'none'
      })
    }
  },
  reject(e) { //驳回
    var that = this;
    var customize = that.data.customize;
    var that = this;
    if (that.data.positionType == 'market') {
      var data = {
        financial_manager_vertify_status: 3,
        rejectReason: customize
      };
      wx.showModal({
        title: '提示',
        content: '是否驳回市场专员审核信息',
        success(res) {
          if (res.confirm) {
            that.finance(data)
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      var data = {
        marketManagerVertifyStatus: 3,
        rejectReason: customize
      };
      wx.showModal({
        title: '提示',
        content: '是否驳回市场专员审核信息',
        success(res) {
          if (res.confirm) {
            that.market(data)
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }

    console.log('驳回理由', customize)
  },
  market(data) { //市场接口
    var that = this;
    getApp().ports.market3({
      data: data,
      id: that.data.id
    }).then((res) => {
      var res = res.data;
      console.log(res)
      if (res.submitTime) that.data.review[0].time = res.submitTime;
      if (res.marketManagerVerificationFinishTime) that.data.review[1].time = res.marketManagerVerificationFinishTime;
      if (res.rejectReason) that.data.review[1].text = '驳回' + ' ' + '驳回理由：' + res.rejectReason
      if (res.marketManagerVertifyStatus == 2) {
        // getApp().ports.zkxg({
        //   data: {
        //     priceYuan: Number(that.data.reviewDetail),
        //     // marketPriceYuan:that.data.information[0].inputs[17].text
        //   },
        //   id: that.data.list.discountHouseId
        // }).then((res) => {
        //   var data = res.data;
        // }).catch(() => {
        //   console.error('出错');
        // });
      }
      that.onApi()
      that.setData({
        list: data,
        review: that.data.review
      })
    }).catch(() => {
      console.error('出错');
    });
  },
  finance(data) { //财务接口
    var that = this;
    getApp().ports.finance3({
      data: data,
      id: that.data.id
    }).then((res) => {
      var res = res.data;
      console.log(res)
      that.data.review[0].time = res.submitTime;
      that.data.review[1].time = res.marketManagerVerificationFinishTime;
      that.data.review[2].time = res.financialManagerVerificationFinishTime;

      that.setData({
        list: res,
        review: that.data.review
      })
    }).catch(() => {
      console.error('出错');
    });
  },
  fwwc() {
    getApp().ports.fanphouse({
      data: {
        stage: 8
      },
      id: that.data.id
    }).then((res) => {
      var res = res.data;
      that.setData({
        active: 4
      })
    }).catch(() => {
      console.error('出错');
    });
  },
  reviewInput(e) {
    this.setData({
      reviewDetail: e.detail.value
    })
  },
  qrcode() {
    var that = this;
    this.setData({
      show: true
    })
    let json = {
      category: 'getwxacodeunlimit'
    } //有个数限制
    var select = that.data.list;
    let inviId = select.id //房源签约id
    let type = that.data.status //订单类型  1优选、2折扣、3放盘
    let userid = wx.getStorageSync('userId') //用户id、绑定当前用户
    let data = {
      appid: getApp().globalData.appid, //小程序id
      path: "pages/index/index", //扫码进入那个页面
      params: JSON.stringify({
        id: inviId,
        type: type,
        userId: userid,
        // housetype: housetype
      }) //房源id、房源类型、订单类型、用户id
    }
    getApp().ports.apiqrcode({
      data,
      json
    }).then((res) => {
      // console.log(res)
      // let base64 = wx.arrayBufferToBase64(res.data)
      that.setData({
        imgurl: 'data:image/png;base64,' + res.data
      })
    }).catch(() => {
      console.error('生成二维码错误！')
    })
  },
  eventSave() {
    var that = this;
    wx.getFileSystemManager().writeFile({
      filePath: wx.env.USER_DATA_PATH + '/wawa.png', //创建一个临时文件名
      data: that.data.imgurl.slice(22), //写入的文本或二进制数据
      encoding: 'base64', //写入当前文件的字符编码
      success: res => {
        wx.saveImageToPhotosAlbum({
          filePath: wx.env.USER_DATA_PATH + '/wawa.png',
          success: function (res) {
            wx.showToast({
              title: '保存图片成功',
              icon: 'success',
              duration: 2000
            })
          },
          fail: function (err) {
            console.log(err)
          }
        })
      },
      fail: err => {
        console.log(err)
      }
    })
  },
  onShowClose() {
    this.setData({
      show: false
    })
  },
})